package org.geektimes.configuration.micro.config.source;

import java.io.IOException;
import java.net.URL;
import java.util.HashMap;
import java.util.Map;
import java.util.Properties;

public class DefaultConfigSource extends MapBasedConfigSource {
    private Map<String, String> fileMap = new HashMap<>();

    public DefaultConfigSource() {
        super("Default File Property", 100);

    }

    @Override
    protected void prepareConfigData(Map<String, String> configData) throws Throwable {
        URL url = Thread.currentThread().getContextClassLoader().getResource("META-INF\\application.properties");
        Properties properties = new Properties();
        try {
            properties.load(url.openStream());
        } catch (IOException e) {
            throw new RuntimeException(e);
        }
        for (String stringPropertyName : properties.stringPropertyNames()) {
            configData.put(stringPropertyName,properties.getProperty(stringPropertyName));
        }
    }
}
